// pages/mine/mine.js
const http = require('../../utils/http.js');
import regeneratorRuntime from '../../lib/runtime/runtime'
Page({
  data: {
    fst:'',
    uid: '',
    title: '',
    balance: '',
    userInfo: {},
    open:true,
    tname:null,
    tel:null,    
    btitle:'点击完善个人信息',
    haseditinfo:false
    
  },
  toinfo: function () {
    //页面跳转
    wx.navigateTo({
      url: '../info/info',
    })
  },
  onShow: function () {
   
    const userInfo=wx.getStorageSync("userInfo")
    const uid=wx.getStorageSync("uid")
    this.setData({
      userInfo,
      uid
    })
    
    if(userInfo.nickName){
      //有授权的用户信息，调取个人信息
      this.get_data()    
     

    }
  },
   
  onLoad: function () {
   


  },
 
 
  async get_data() {

   
    let url = 'client/detailandfst';
    let data = {
      uid: this.data.uid,
    }
    let res= await http.post(url,data)
    
    if (res.client.name == null) {
      //没有名字信息，跳转到地址页面让用户填写信息
      this.setData({
        btitle: '点击完善个人信息',          
        haseditinfo: false
      })

    } else {
      /* wx.setStorage({
         key: 'address',
         data: res,         
       })*/
       wx.setStorageSync('tname',res.client.name) //保存用户的姓名
       this.setData({
        haseditinfo: true,
        btitle: '修改个人信息', 
        tname: res.client.name,
        tel: res.client.tel,
        fst: res.fst
      })
    }


  },
  
  myAddress: function (e) {
    wx.navigateTo({ url: '../addressList/addressList' });
  }
})
